package com.uh.calculation.util;

import com.uh.calculation.bean.TbFeild;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GetBean {



    public static Map<String,String> getMap(String fieldNames){
        Map <String,String>  map = new HashMap<>();
        try {
            String feildName [] = fieldNames.split("\\|");

            for(String st:feildName){
                map.put(st,"");
            }

        }catch (Exception E){

        }
        return map;
    }


    public static String   fieldVal(Object obj,String fieldName){
        try {
            Field field = obj.getClass().getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(obj).toString();

        }catch (Exception E){

        }
        return null;
    }
    //解析字段表名
    public static List<TbFeild> getTbf(String   field){
        List<TbFeild>  tbFeilds = new ArrayList<>();
        try {
            String   str[] = field.split(";");
            for(String s:str){
                TbFeild tbFeild = new TbFeild();
                String ss = "";
                if(s.contains("$")){
                    ss = s.replace("$", "");//针对同字段不同周期比较时加入的状态值
                    if (ss.contains("#m")) {
                        ss = ss.replace("#m", "");//针对同字段不同周期比较时加入的状态值
                        tbFeild.setSort(0);
                    }
                    tbFeild.setFieldName(ss);
                    tbFeild.setOriginalName(s);
                    tbFeilds.add(tbFeild);
                }else {
                    if (s.contains("#m")) {
                        ss = s.replace("#m", "");//针对同字段不同周期比较时加入的状态值
                        tbFeild.setSort(0);

                    } else {
                        tbFeild.setSort(1);
                        ss = s;
                    }
                    String st[] = ss.split("_");
                    tbFeild.setFieldName(st[1]);
                    tbFeild.setTabName(st[0]);
                    tbFeild.setOriginalName(s);
                    tbFeilds.add(tbFeild);
                }
            }
        }catch (Exception E){
        }
        return tbFeilds;
    }
}
